<?php

class Core_Table_Global_Module extends Kd_Data_Table {

    public function __construct() {
        parent::__construct();
    }

    public function deleteAreaRelation($moduleId, $transaction = NULL) {
        Kd_Data_Factory::getDeleteDcl()
                ->from('{t}global_module_area')
                ->where()
                ->eq('module_id', ':moduleId:s')
                ->closest()
                ->addParameter(array('moduleId' => $moduleId))
                ->setDbDriver($this->getDbDriver($transaction))
                ->execute();
        return $this;
    }

    public function insertAreaRelation($moduleId, array $areaIds, $transaction = NULL) {
        $insert = Kd_Data_Factory::getInsertDcl()
                        ->into('{t}global_module_area')
                        ->value('module_id', ':moduleId:s')
                        ->value('area_id', ':areaId:s')
                        ->toSql();
        $driver = $this->getDbDriver($transaction);
        foreach ($areaIds as $areaId) {
            $driver->setSql($insert, array('moduleId' =>$moduleId, 'areaId' =>$areaId))
                   ->execute();
        }

        return $this;
    }

}


